package com.jnu.tijian.service;

import com.jnu.tijian.domain.Orders;
import com.jnu.tijian.dto.ResponseObject;
import com.jnu.tijian.exception.TijianAPPException;
import com.jnu.tijian.exception.TijianAPPExceptionEnum;
import com.jnu.tijian.mapper.OrdersMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestBody;

@Service
public class OrdersServiceImpl implements OrdersService {
    @Autowired
    OrdersMapper ordersMapper;

    @Override
    public ResponseObject saveOrders(@RequestBody Orders orders){
        // 先查询订单表 查看当天是否预约
        if(ordersMapper.selectByPrimaryKey(orders.getOrderId()) != null){
            // 如果有预约 则抛出异常
            throw new TijianAPPException(TijianAPPExceptionEnum.ALREADY_APPOINTMENT_CURRENT_DAY.getCode(), TijianAPPExceptionEnum.ALREADY_APPOINTMENT_CURRENT_DAY.getMessage());
        }
        ordersMapper.insert(orders);
        return new ResponseObject(ResponseObject.SUCCESS_STATUS, ResponseObject.SUCCESS_DESC);
    }
}
